package com.fary.mapper;

import com.fary.base.BaseMapper;
import com.fary.dto.MenuIndexDto;
import com.fary.po.MyMenu;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface MenuMapper extends BaseMapper<MyMenu> {

    @Select("SELECT DISTINCT m.menu_id   AS id,\n" +
            "                m.parent_id,\n" +
            "                m.menu_name AS title,\n" +
            "                m.icon,\n" +
            "                m.url       AS href,\n" +
            "                m.type,\n" +
            "                m.permission,\n" +
            "                m.sort\n" +
            "FROM my_role_user ru\n" +
            "         INNER JOIN my_role_menu rm ON rm.role_id = ru.role_id\n" +
            "         LEFT JOIN my_menu m ON rm.menu_id = m.menu_id\n" +
            "ORDER BY ifnull(m.sort, 0)")
    List<MenuIndexDto> listByUserId(Integer userId);
}
